gl renderer: Proper state tracking for color matrix ops
authorTimm Bäder <mail@baedert.org>
Fri, 18 Dec 2020 17:28:17 +0000 (18:28 +0100)
committerTimm Bäder <mail@baedert.org>
Mon, 21 Dec 2020 09:26:03 +0000 (10:26 +0100)
gsk/gl/gskglrenderer.c
gsk/gl/gskglrenderops.c
gsk/gl/opbuffer.h

index 4af89c5258c76ef8a031c5825ca854d545095b79..89cc3684ce3944d736e69f9f49590ad07aaade98 100644 (file)
@@ -2940,10 +2940,15 @@ static inline void
 apply_color_matrix_op (const Program       *program,
                        const OpColorMatrix *op)
 {
-  float mat[16];
-  OP_PRINT (" -> Color Matrix");
-  graphene_matrix_to_float (op->matrix, mat);
-  glUniformMatrix4fv (program->color_matrix.color_matrix_location, 1, GL_FALSE, mat);
+  OP_PRINT (" -> Color matrix. Send matrix: %d. Send offset: %d.",
+            op->matrix.send, op->offset.send);
+
+  if (op->matrix.send)
+    {
+      float mat[16];
+      graphene_matrix_to_float (op->matrix.value, mat);
+      glUniformMatrix4fv (program->color_matrix.color_matrix_location, 1, GL_FALSE, mat);
+    }
 
   if (op->offset.send)
     {
index be7eff6fba7039048d1f5ddef21ea3c31e75b019..d7639162ad03d61ab22bcd9e4cafe776b64ef90b 100644 (file)
@@ -533,30 +533,30 @@ ops_set_color_matrix (RenderOpBuilder         *builder,
                       const graphene_vec4_t   *offset)
 {
   ProgramState *current_program_state = get_current_program_state (builder);
+  const bool offset_equal = graphene_vec4_equal (offset, &current_program_state->color_matrix.offset);
+  const bool matrix_equal = graphene_matrix_equal_fast (matrix,
+                                                        &current_program_state->color_matrix.matrix);
   OpColorMatrix *op;
-  bool offset_equal;
 
-  offset_equal = memcmp (offset,
-                         &current_program_state->color_matrix.offset,
-                         sizeof (graphene_vec4_t)) == 0;
-
-  if (memcmp (matrix,
-              &current_program_state->color_matrix.matrix,
-              sizeof (graphene_matrix_t)) == 0 &&
-      offset_equal)
+  if (offset_equal && matrix_equal)
     return;
 
-  current_program_state->color_matrix.matrix = *matrix;
-
   op = ops_begin (builder, OP_CHANGE_COLOR_MATRIX);
-  op->matrix = matrix;
+
+  if (!matrix_equal)
+    {
+      current_program_state->color_matrix.matrix = *matrix;
+      op->matrix.value = matrix;
+      op->matrix.send = TRUE;
+    }
+  else
+    op->matrix.send = FALSE;
 
   if (!offset_equal)
     {
+      current_program_state->color_matrix.offset = *offset;
       op->offset.value = offset;
       op->offset.send = TRUE;
-
-      current_program_state->color_matrix.offset = *offset;
     }
   else
     op->offset.send = FALSE;
index 08f48b7c5fa1d0cebb1a589528281696d23e1478..db9b5c9425933e5a50c826325955e53608b6d3c4 100644 (file)
@@ -53,6 +53,7 @@ typedef struct { GskRoundedRect value; guint send: 1; guint send_corners: 1; } R
 typedef struct { const GdkRGBA *value; guint send: 1; } RGBAUniformValue;
 typedef struct { const graphene_vec4_t *value; guint send: 1; } Vec4UniformValue;
 typedef struct { const GskColorStop *value; guint send: 1; } ColorStopUniformValue;
+typedef struct { const graphene_matrix_t *value; guint send: 1; } MatrixUniformValue;
 
 /* OpNode are allocated within OpBuffer.pos, but we keep
  * a secondary index into the locations of that buffer
@@ -167,7 +168,7 @@ typedef struct
 
 typedef struct
 {
-  const graphene_matrix_t *matrix;
+  MatrixUniformValue matrix;
   Vec4UniformValue offset;
 } OpColorMatrix;